﻿namespace Digitalmes.Domain.Mes;

/// <summary>
/// 班次
/// </summary>
[SugarTable("md_shift", "班次表")]
public class MdShift : EntityBase
{
    // <summary>
    /// 班次编号
    /// <remarks>白班（Day Shift）；夜班（Night Shift）</remarks>
    /// </summary>
    [NotNull]
    [SugarColumn(ColumnDescription = "班次编号", Length = 32)]
    public string? ShiftCode { get; set; }

    /// <summary>
    /// 班次名称
    /// </summary>
    [NotNull]
    [SugarColumn(ColumnDescription = "班次名称", Length = 32)]
    public string? ShiftName { get; set; }

    /// <summary>
    /// 开始时间点（24小时制），如 08:30
    /// </summary>
    [NotNull]
    [SugarColumn(ColumnDescription = "开始时间点", Length = 8)]
    public string? BeginTime { get; set; }

    /// <summary>
    /// 结束时间点（24小时制），如 18:30
    /// </summary>
    [NotNull]
    [SugarColumn(ColumnDescription = "结束时间点", Length = 8)]
    public string? EndTime { get; set; }

    /// <summary>
    /// 生效日期
    /// </summary>
    [SugarColumn(ColumnDescription = "生效日期")]
    public DateTime EffectiveDate { get; set; }

    /// <summary>
    /// 失效日期，包括当天。
    /// </summary>
    [SugarColumn(ColumnDescription = "失效日期")]
    public DateTime ExpiryDate { get; set; }

    /// <summary>
    /// 检测时间是否处于班次设置时间内
    /// </summary>
    /// <param name="now">时间</param>
    /// <returns></returns>
    public bool IsIn(DateTime now)
    {
        var begin = TimeOnly.Parse(BeginTime);
        var end = TimeOnly.Parse(EndTime);

        TimeOnly time = new(now.Hour, now.Minute);
        return time.IsBetween(begin, end);
    }
}
